package com.rose.datax.dataxadmin.action;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rose.datax.dataxadmin.utils.TypeUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseAction {

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    protected <T> Page<T> getPage() {
        int index = 1;
        Integer pageNo = TypeUtils.castToInt(request.getParameter("pageNo"), index);

        Integer pageSize = TypeUtils.castToInt(request.getParameter("pageSize"), 20);
        Boolean searchCount = TypeUtils.castToBoolean(request.getParameter("searchCount"), true);
        return new Page<>(pageNo, pageSize, searchCount);
    }
}
